from config import *
from tools import create_sprite


class Mine(object):
    """
    地雷
    """

    HIDE = {"img":"blank"}      # 隐藏状态
    FLAG = {"img":"flag"}       # 标记状态
    DIE = {"img":"blood"}       # 炸弹爆炸
    MINE = {"img":"mine"}       # 炸弹
    N0 = {"img":"0"}
    N1 = {"img":"1"}
    N2 = {"img": "2"}
    N3 = {"img": "3"}
    N4 = {"img": "4"}
    N5 = {"img": "5"}
    N6 = {"img": "6"}
    N7 = {"img": "7"}
    N8 = {"img": "8"}

    def __init__(self, x, y):
        self.x = x
        self.y = y
        self.state = Mine.HIDE # 默认为隐藏状态
        self.__is_bomb = False # 是不是真地雷

    def __str__(self):
        # return "%02d:%02d" % (self.y, self.x) # 测试逻辑坐标
        # return "%d" % self.state # 测试状态
        if self.__is_bomb:
            return "1"
        else:
            return "0"

    def draw(self, screen):
        """地雷绘制"""
        pos = (self.x * SIZE, (self.y + 2) * SIZE)
        img = create_sprite(self.state["img"], SIZE, SIZE)
        screen.blit(img, pos)

    def set_bomb(self):
        """设置为炸弹"""
        self.__is_bomb = True

    def is_bomb(self):
        """是否是炸弹"""
        return self.__is_bomb

    def show_bomb(self):
        """显示炸弹"""
        self.state = Mine.MINE

    def show_die(self):
        """显示死亡状态"""
        self.state = Mine.DIE

    def show_around_num(self, num):
        """显示周围的地雷数量"""
        tuple1 = (Mine.N0, Mine.N1, Mine.N2, Mine.N3, Mine.N4, Mine.N5, Mine.N6, Mine.N7, Mine.N8)
        self.state = tuple1[num]
